package com.homedo.microservice.open.service.gateway.manager.web.gateway.persistence.dao;

import com.homedo.common.bean.vo.Pagination;
import com.homedo.common.dao.BaseDao;
import com.homedo.common.util.Detect;
import com.homedo.microservice.open.service.gateway.manager.web.gateway.bean.po.RouteService;
import com.homedo.microservice.open.service.gateway.manager.web.gateway.bean.query.RouteServiceQuery;
import com.homedo.microservice.open.service.gateway.manager.web.gateway.persistence.mapper.IRouteServiceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;


/**
 * @author 作者 jgshun
 * @date 创建时间 2018年09月18日 11时30分20秒
 */
@Repository
public class RouteServiceDao extends BaseDao<RouteService> {
    @Autowired
    private IRouteServiceMapper routeServiceMapper;

    public Pagination<RouteService> getPagination(RouteServiceQuery routeServiceQuery, Pagination<RouteService> pagination) {
        Example example = new Example(RouteService.class);
        Example.Criteria criteria = example.createCriteria();

        if (Detect.notEmpty(routeServiceQuery.getApplicationNames())) {
            criteria.andIn(RouteService.FIELD_APPLICATIONNAME, routeServiceQuery.getApplicationNames());
        }
        if (Detect.notEmpty(routeServiceQuery.getLikeComment())) {
            criteria.andLike(RouteService.FIELD_COMMENT, "%" + routeServiceQuery.getLikeComment() + "%");
        }
        if (Detect.notEmpty(routeServiceQuery.getLikeId())) {
            criteria.andLike(RouteService.FIELD_ID, "%" + routeServiceQuery.getLikeId() + "%");
        }
        if (Detect.notEmpty(routeServiceQuery.getStatuses())) {
            criteria.andIn(RouteService.FIELD_STATUS, routeServiceQuery.getStatuses());
        }

        return super.getPagination(pagination, example);
    }
}
